package com.osce.common.utils.oesc;

import com.doudou.core.container.ListUtil;

import java.util.List;

/**
 * @author zzxjs
 * @since 2023/9/7
 */
public class PlaceModel {

    /**
     * 考场编号
     */
    private Long id;

    private Integer placeCount;

    /**
     * 考试时间 分钟
     */
    private Integer exTime;

    /**
     * 房间内是否有人,初始化没有
     */
    private Boolean nasPeoPle = false;

    /**
     * 当前房间考生代号
     */
    private String code;

    /**
     * 需要等待的时间 分，初始化没不等待
     */
    private Integer waitMinute = 0;
    private Integer peopleExamMinute = 0;

    /**
     * 已经进入房间的人员
     */
    private List<PlaceAllotBean> placeAllotList = ListUtil.linkedList();

    public PlaceModel() {
    }

    public PlaceModel(Long id, Integer exTime) {
        this.id = id;
        this.exTime = exTime;
    }

    public PlaceModel(Long id, Integer exTime, Integer placeCount) {
        this.id = id;
        this.exTime = exTime;
        this.placeCount = placeCount;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getPlaceCount() {
        return placeCount;
    }

    public void setPlaceCount(Integer placeCount) {
        this.placeCount = placeCount;
    }

    public Integer getExTime() {
        return exTime;
    }

    public void setExTime(Integer exTime) {
        this.exTime = exTime;
    }

    public Boolean getNasPeoPle() {
        return nasPeoPle;
    }

    public void setNasPeoPle(Boolean nasPeoPle) {
        this.nasPeoPle = nasPeoPle;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getWaitMinute() {
        return waitMinute;
    }

    public void setWaitMinute(Integer waitMinute) {
        this.waitMinute = waitMinute;
    }

    public Integer getPeopleExamMinute() {
        return peopleExamMinute;
    }

    public void setPeopleExamMinute(Integer peopleExamMinute) {
        this.peopleExamMinute = peopleExamMinute;
    }

    public List<PlaceAllotBean> getPlaceAllotList() {
        return placeAllotList;
    }

    public void setPlaceAllotList(List<PlaceAllotBean> placeAllotList) {
        this.placeAllotList = placeAllotList;
    }

    /**
     * 格式化等待时间 考试时间 + 休息时间
     */
    public void parseWaitMinute(Integer interval_M) {
        this.waitMinute = this.exTime + interval_M;
    }

    /**
     * 添加等待时间
     */
    public void addWaitMinute(Integer num) {
        this.waitMinute+=num;
    }

    /**
     * 等待时间减一
     * @return 如果等待时间=0，返回当前考生，用于使用者修改考生等待状态
     */
    public String minusWaitMinute(int num) {
        this.waitMinute-=num;
        this.peopleExamMinute -= this.peopleExamMinute==0 ? 0 : num;//学生考试时间减一
        String str = null;
        if (this.peopleExamMinute==0){//学生考完
            str = this.code;
        }
        if (this.waitMinute == 0){//如果等待时间=0，说明考场已空，返回当前考生
            this.nasPeoPle = false;
        }
        return str;
    }


    public void addPlaceAllot(PlaceAllotBean placeAllot) {
        this.placeAllotList.add(placeAllot);
    }

    public void addAllPlaceAllot(List<PlaceAllotBean> placeAllots) {
        this.placeAllotList.addAll(placeAllots);
    }


    @Override
    public String toString() {
        return "PlaceModel{" +
                "id=" + id +
                ", placeCount=" + placeCount +
                ", exTime=" + exTime +
                ", nasPeoPle=" + nasPeoPle +
                ", code='" + code + '\'' +
                ", waitMinute=" + waitMinute +
                ", peopleExamMinute=" + peopleExamMinute +
                '}';
    }
}
